package com.fangmou.ing.util;

/**
 * Created : 11-7-29 上午9:59
 * By      : liming
 */
public class PathUtils {

    public static String getWebClassesPath() {
        String path = PathUtils.class.getProtectionDomain().getCodeSource()
                .getLocation().getPath();
        return path;

    }

    public static String getWebInfPath() throws IllegalAccessException {
        String path = getWebClassesPath();
        if (path.indexOf("WEB-INF") > 0) {
            path = path.substring(0, path.indexOf("WEB-INF") + 8);
        } else {
            throw new IllegalAccessException("路径WEB-INF获取失败:" + path);
        }
        return path;
    }

    public static String getWebRoot() throws IllegalAccessException {
        String path = getWebClassesPath();
        if (path.indexOf("WEB-INF") > 0) {
            path = path.substring(0, path.indexOf("WEB-INF/classes"));
        } else {
            throw new IllegalAccessException("路径WebRoot获取失败:" + path);
        }
        return path;
    }
}
